﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Chat
{
    /// <summary>
    /// Wraps the integer value used to represent the IP port number.
    /// The class implemented in a way, that doesn't alow to create
    /// or modify instanses with invalid port number value.
    /// </summary>
    public struct PortNumber
    {
        /// <summary>
        /// The port number value.
        /// </summary>
        private int value;

        public PortNumber(int value)
        {
            this.value = 0;
            Value = value;
        }

        /// <summary>
        /// Gets or sets the port number value.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// When trying to set illegal value for the port number.
        /// </exception>
        public int Value
        {
            get { return this.value; }

            set
            {
                if (value < IPEndPoint.MinPort || value > IPEndPoint.MaxPort)
                    throw new ArgumentOutOfRangeException(
                        "value", "The specified port number not in allowed range");

                this.value = value;
            }
        }
    }
}
